package cn.car.biz.carAccess.support;

import cn.car.domains.enums.InoutTypeEnum;
import cn.car.exception.CarAccessControlException;
import jakarta.annotation.Resource;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class PlateDetectedSupportFactory {


    @Resource
    private ApplicationContext applicationContext;

    @Resource
    private List<PlateDetectedSupport> plateDetectedSupportList;

    public PlateDetectedSupport getSupport(String vehicleType, String inOutType) {

        if (vehicleType == null && inOutType.equals(InoutTypeEnum.out.name())) {
            return applicationContext.getBean("commonSupport", PlateDetectedSupport.class);
        }

        for (PlateDetectedSupport plateDetectedSupport : plateDetectedSupportList) {
            if (plateDetectedSupport.supportName().equals(vehicleType)) {
                return plateDetectedSupport;
            }
        }




        throw CarAccessControlException.IMPL_NOT_EXIST.newInstance("No implementation found for vehicle type: {0}", vehicleType);
    }

}
